// 使用 Element Plus 微应用统一配置
import { createSimpleTDesignHttpInstance } from '@tuxing/network-http';
import { ElMessage, ElMessageBox, ElLoading } from 'element-plus';

// 创建预配置的请求实例
export const request = createSimpleTDesignHttpInstance({
  MessagePlugin: ElMessage,
  DialogPlugin: ElMessageBox,
  LoadingPlugin: ElLoading,
});

/**
 * 下载文件
 */
export function download(url: string, filename?: string) {
  const link = document.createElement('a');
  link.href = url;
  if (filename) {
    link.download = filename;
  }
  link.style.display = 'none';
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}

export default request;